package com.example.controller;
import com.example.exception.CustomException;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.*;
import com.example.service.*;
import com.example.service.impl.CollectServiceImpl;
import com.example.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/front")
public class FrontController {
    @Autowiredprivate DingdanxinxiService  dingdanxinxiService;@Autowiredprivate YonghuxinxiService  yonghuxinxiService;@Autowiredprivate GuoyuanxinxiService  guoyuanxinxiService;@Autowiredprivate CaizhaiyuyueService  caizhaiyuyueService;@Autowiredprivate KucunxinxiService  kucunxinxiService;@Autowiredprivate RukuxinxiService  rukuxinxiService;@Autowiredprivate ChukuxinxiService  chukuxinxiService;
    @Autowired
    private PinglunService pinglunService;
	@Autowired
    private XitongjianjieService xitongjianjieService;
	@Autowired
    private BianhuantuService  bianhuantuService;
    @Autowired
    private XinwentongzhiService  xinwentongzhiService;
    @Autowired
    private LiuyanbanService liuyanbanService;
    @Resource
    private CollectServiceImpl collectService;

	@GetMapping("/getdingdanxinxidetail/{id}")public Result getdingdanxinxidetail(@PathVariable Integer id) {	return Result.success(dingdanxinxiService.findById(id));}@PostMapping("/dingdanxinxi")public Result<DingdanxinxiVo> dingdanxinxi(@RequestBody DingdanxinxiVo dingdanxinxiVo) {return Result.success(dingdanxinxiService.findPage(dingdanxinxiVo));}@PostMapping("/postdingdanxinxi")public Result<Dingdanxinxi> postdingdanxinxi(@RequestBody Dingdanxinxi dingdanxinxi) {return Result.success(dingdanxinxiService.add(dingdanxinxi));}@GetMapping("/getyonghuxinxidetail/{id}")public Result getyonghuxinxidetail(@PathVariable Integer id) {	return Result.success(yonghuxinxiService.findById(id));}@PostMapping("/yonghuxinxi")public Result<YonghuxinxiVo> yonghuxinxi(@RequestBody YonghuxinxiVo yonghuxinxiVo) {return Result.success(yonghuxinxiService.findPage(yonghuxinxiVo));}@PostMapping("/postyonghuxinxi")public Result<Yonghuxinxi> postyonghuxinxi(@RequestBody Yonghuxinxi yonghuxinxi) {return Result.success(yonghuxinxiService.add(yonghuxinxi));}@PostMapping("/loginyonghuxinxi")public Result loginyonghuxinxi(@RequestBody Yonghuxinxi yonghuxinxi) {return Result.success(yonghuxinxiService.login(yonghuxinxi));}@GetMapping("/getguoyuanxinxidetail/{id}")public Result getguoyuanxinxidetail(@PathVariable Integer id) {	return Result.success(guoyuanxinxiService.findById(id));}@PostMapping("/guoyuanxinxi")public Result<GuoyuanxinxiVo> guoyuanxinxi(@RequestBody GuoyuanxinxiVo guoyuanxinxiVo) {return Result.success(guoyuanxinxiService.findPage(guoyuanxinxiVo));}@PostMapping("/postguoyuanxinxi")public Result<Guoyuanxinxi> postguoyuanxinxi(@RequestBody Guoyuanxinxi guoyuanxinxi) {return Result.success(guoyuanxinxiService.add(guoyuanxinxi));}@GetMapping("/getcaizhaiyuyuedetail/{id}")public Result getcaizhaiyuyuedetail(@PathVariable Integer id) {	return Result.success(caizhaiyuyueService.findById(id));}@PostMapping("/caizhaiyuyue")public Result<CaizhaiyuyueVo> caizhaiyuyue(@RequestBody CaizhaiyuyueVo caizhaiyuyueVo) {return Result.success(caizhaiyuyueService.findPage(caizhaiyuyueVo));}@PostMapping("/postcaizhaiyuyue")public Result<Caizhaiyuyue> postcaizhaiyuyue(@RequestBody Caizhaiyuyue caizhaiyuyue) {return Result.success(caizhaiyuyueService.add(caizhaiyuyue));}@GetMapping("/getkucunxinxidetail/{id}")public Result getkucunxinxidetail(@PathVariable Integer id) {	return Result.success(kucunxinxiService.findById(id));}@PostMapping("/kucunxinxi")public Result<KucunxinxiVo> kucunxinxi(@RequestBody KucunxinxiVo kucunxinxiVo) {return Result.success(kucunxinxiService.findPage(kucunxinxiVo));}@PostMapping("/postkucunxinxi")public Result<Kucunxinxi> postkucunxinxi(@RequestBody Kucunxinxi kucunxinxi) {return Result.success(kucunxinxiService.add(kucunxinxi));}@GetMapping("/getrukuxinxidetail/{id}")public Result getrukuxinxidetail(@PathVariable Integer id) {	return Result.success(rukuxinxiService.findById(id));}@PostMapping("/rukuxinxi")public Result<RukuxinxiVo> rukuxinxi(@RequestBody RukuxinxiVo rukuxinxiVo) {return Result.success(rukuxinxiService.findPage(rukuxinxiVo));}@PostMapping("/postrukuxinxi")public Result<Rukuxinxi> postrukuxinxi(@RequestBody Rukuxinxi rukuxinxi) {return Result.success(rukuxinxiService.add(rukuxinxi));}@GetMapping("/getchukuxinxidetail/{id}")public Result getchukuxinxidetail(@PathVariable Integer id) {	return Result.success(chukuxinxiService.findById(id));}@PostMapping("/chukuxinxi")public Result<ChukuxinxiVo> chukuxinxi(@RequestBody ChukuxinxiVo chukuxinxiVo) {return Result.success(chukuxinxiService.findPage(chukuxinxiVo));}@PostMapping("/postchukuxinxi")public Result<Chukuxinxi> postchukuxinxi(@RequestBody Chukuxinxi chukuxinxi) {return Result.success(chukuxinxiService.add(chukuxinxi));}
	
	@GetMapping("/getxitongjianjiedetailblb/{lb}")
    public Result getxitongjianjiedetailblb(@PathVariable String lb) {
        return Result.success(xitongjianjieService.findByZhujian(lb));
    }
	@PostMapping("/postpinglun")
    public Result<Pinglun> postpinglun(@RequestBody Pinglun pinglun) {
        return Result.success(pinglunService.add(pinglun));
    }
    @PostMapping("/pinglun")
    public Result<PinglunVo> pinglun(@RequestBody PinglunVo pinglunVo) {
        return Result.success(pinglunService.findPage(pinglunVo));
    }
	
	@GetMapping("/bianhuantu")
    public Result bianhuantu() {
        return Result.success(bianhuantuService.list());
    }
   
    @GetMapping("/xinwentongzhi")
    public Result xinwentongzhi() {
        return Result.success(xinwentongzhiService.list());
    }
    @GetMapping("/getxinwentongzhi/{id}")
    public Result getxinwentongzhi(@PathVariable Integer id) {
        return Result.success(xinwentongzhiService.findById(id));
    }
	@PutMapping("/xinwentongzhi")
    public Result updateXinwentongzhi(@RequestBody XinwentongzhiVo xinwentongzhi) {
        xinwentongzhiService.update(xinwentongzhi);
        return Result.success();
    }
    @PostMapping("/addLiuyan")
    public Result addComment(@RequestBody Liuyanban liuyanban) {
        liuyanbanService.add(liuyanban);
        return Result.success();
    }
    @GetMapping("/getLiuyan")
    public Result<List<Liuyanban>> getCommentTiezi() {
        return Result.success(liuyanbanService.getLiuyan());
    }
    @PostMapping("/addCollect")
    public Result addCollect(@RequestBody Collect collect) {
        Collect collect1 = collectService.add(collect);
        if(collect1  == null){
            return Result.success("请勿重复收藏");
        }
        return Result.success();
    }
    @DeleteMapping("/deleteCollect/{id}")
    public Result deleteCollect(@PathVariable Integer id) {
        collectService.delete(id);
        return Result.success();
    }
	@PostMapping("/getUserCollect")
    public Result getUserCollect(@RequestBody Collect collect) {
        return Result.success(collectService.findFrontPages(collect.getUserId()));
    }
    @DeleteMapping("/deleteCollect/{id}/{userId}")
    public Result deleteCollect(@PathVariable Integer id,@PathVariable Integer userId) {
        collectService.deleteByUserId(id,userId);
        return Result.success();
    }
	
	@PutMapping("/dingdanxinxi")public Result updateDingdanxinxi(@RequestBody DingdanxinxiVo dingdanxinxi) {dingdanxinxiService.update(dingdanxinxi);return Result.success();}@PutMapping("/yonghuxinxi")public Result updateYonghuxinxi(@RequestBody YonghuxinxiVo yonghuxinxi) {yonghuxinxiService.update(yonghuxinxi);return Result.success();}@PutMapping("/guoyuanxinxi")public Result updateGuoyuanxinxi(@RequestBody GuoyuanxinxiVo guoyuanxinxi) {guoyuanxinxiService.update(guoyuanxinxi);return Result.success();}@PutMapping("/caizhaiyuyue")public Result updateCaizhaiyuyue(@RequestBody CaizhaiyuyueVo caizhaiyuyue) {caizhaiyuyueService.update(caizhaiyuyue);return Result.success();}@PutMapping("/kucunxinxi")public Result updateKucunxinxi(@RequestBody KucunxinxiVo kucunxinxi) {kucunxinxiService.update(kucunxinxi);return Result.success();}@PutMapping("/rukuxinxi")public Result updateRukuxinxi(@RequestBody RukuxinxiVo rukuxinxi) {rukuxinxiService.update(rukuxinxi);return Result.success();}@PutMapping("/chukuxinxi")public Result updateChukuxinxi(@RequestBody ChukuxinxiVo chukuxinxi) {chukuxinxiService.update(chukuxinxi);return Result.success();}

}
